package main

import (
	_ "travelservia/routers"
	_ "github.com/go-sql-driver/mysql"
	_ "travelservia/models"
	"github.com/astaxie/beego"
	"os"
	"github.com/astaxie/beego/orm"
	"github.com/astaxie/beego/logs"
)
func init() {
	env := os.Getenv("ENV_TRAVEL")
	if env == "ONLINE" {
		beego.LoadAppConfig("ini", "conf/app_online.conf")
		orm.RegisterDataBase("default", "mysql", "root:estate@2017@tcp(127.0.0.1:3306)/jianfa?charset=utf8&loc=Local")
	} else if env == "ONLINETEST" {
		beego.LoadAppConfig("ini", "conf/app_test.conf")
		orm.RegisterDataBase("default", "mysql", "root:chill@mysql@tcp(127.0.0.1:3306)/travelservia_dev?charset=utf8&loc=Local")
	} else {
		beego.LoadAppConfig("ini", "conf/app.conf")
		orm.RegisterDataBase("default", "mysql", "root:vrjiaju2016mysql@tcp(127.0.0.1:3306)/travelservia_dev?charset=utf8&loc=Local")
	}
	orm.RunSyncdb("default", false, true)
	logs.NewLogger(10000)
	logs.SetLogger(logs.AdapterFile, `{"filename":"project.log","level":7,"maxlines":0,"maxsize":0,"daily":true,"maxdays":10}`)
}

func main() {
	setStaticPath()
	beego.Run()
}

func setStaticPath() {
	beego.SetStaticPath("/js", "views/js")
	beego.SetStaticPath("/img", "views/img")
	beego.SetStaticPath("/css", "views/css")
	beego.SetStaticPath("/uploads", beego.AppConfig.String("uploadspath"))

}